<template>
	<view class="content">
		<u-navbar bgColor="#fff" :placeholder="true" :fixed="true" @leftClick="$back" title="更多设置" titleStyle="{'color': '#000'}">
			
		</u-navbar>
		<view class="baibox">
			<view class="baili" @click="$go('/pages/user/data')">
				<image :src="'/images/grzl.png'  | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					个人资料
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>


			<view class="baili" @click="$go('/showcase/user/account_set')">
				<image :src="'/images/217.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					账号安全
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
			
			<!-- <view class="baili" @click="$go('/showcase/user/tui_set')">
				<image :src="'/images/tui.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					推送设置
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view> -->


			<view class="baili" @click="$go('/pages/user/yinsi')">
				<image :src="'/images/yinsi.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					隐私设置
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>

			<view class="baili" @click="$go('/pages/user/pingbi')">
				<image :src="'/images/pingbi.png'  | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					屏蔽设置
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
			<!-- 	<view class="baili" @click="$go('/pages/user/manage')" v-if="userInfo.is_writer">
				<image :src="'/images/xb.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					展示设置
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view> -->
			<view class="baili" @click="$go('/pages/user/record')">
				<image :src="'/images/xc1.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					举报记录
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>

			<!-- 10.16新增 -->
			<view class="baili" @click="$go('/showcase/showcase/invoice')">
				<image :src="'/images/fapiao.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					开具发票
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>

			<view class="baili" @click="$go('/pages/user/log')">
				<image :src="'/images/xd1.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					日志清单
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>

			<view class="baili" @click="$go('/pages/user/abount')">
				<image :src="'/images/abount.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					关于我们
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
			<!-- 	
			<view class="baili" @click="$go('/pages/login/hobby?type=1')">
				<image :src="'/images/abount.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					偏好设置
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view> -->
			<!-- #ifdef APP-PLUS -->
			<view class="baili" @click="clearStorage">
				<image :src="'/images/217.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					清除缓存
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
			<!-- #endif -->

		</view>

		<!-- <view class="baibox">
			<view class="baili" >
				<image :src="'/images/abount.png' | formatImgUrl" class="pic" mode=""></image>
				<view class="txt">
					系统权限
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>
		</view> -->


		<view class="tuibox" @click="outLogin">
			<image :src="'/images/xe5.png' | formatImgUrl" class="tpic" mode=""></image>
			<view class="ttxt">
				退出登录
			</view>
		</view>
	</view>
</template>
<script>
	import * as db from '@/common/db.js'
	import TUIChatEngine,{TUIStore,StoreName} from "@tencentcloud/chat-uikit-engine";
	export default {
		data() {
			return {
				userInfo: this.$db.get('userInfo'),
				fileSizeString: ''
			}
		},
		onLoad() {
			let auth = db.get('auth');
			console.log(auth, 777777777)
			//用户存在，不跳转，不存在直接跳转
			if (!auth) {
				// toLogin()
				uni.navigateTo({

					url: '/pages/login/login'

				})
				return
			}

		},
		onShow() {
			// this.getUserInfo()
		},
		methods: {
			// 清除缓存
			clearStorage() {
				uni.showModal({
					title: '清除缓存',
					content: '您确定要清除缓存吗？',
					success: (res) => {
						if (res.confirm) {
							console.log('用户点击确定');
							this.clearCache();
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			clearCache() {
				let os = plus.os.name;
				if (os == 'Android') {
					let main = plus.android.runtimeMainActivity();
					let sdRoot = main.getCacheDir();
					let files = plus.android.invoke(sdRoot, "listFiles");
					let len = files.length;
					for (let i = 0; i < len; i++) {
						let filePath = '' + files[i];
						plus.io.resolveLocalFileSystemURL(filePath, (entry) => {
							if (entry.isDirectory) {
								entry.removeRecursively((entry) => {
									uni.showToast({
										title: '缓存清理完成',
										duration: 2000
									});
									this.formatSize();
								}, (e) => {
									console.log(e.message)
								});
							} else {
								entry.remove();
							}
						}, (e) => {
							console.log('文件路径读取失败')
						});
					}
				} else { // ios  
					plus.cache.clear(() => {
						uni.showToast({
							title: '缓存清理完成',
							duration: 2000
						});
						this.formatSize();
					});
				}
			},
			formatSize() {
				plus.cache.calculate((size) => {
					let sizeCache = parseInt(size);
					if (sizeCache == 0) {
						this.fileSizeString = "0B";
					} else if (sizeCache < 1024) {
						this.fileSizeString = sizeCache + "B";
					} else if (sizeCache < 1048576) {
						this.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB";
					} else if (sizeCache < 1073741824) {
						this.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB";
					} else {
						this.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB";
					}
				});
			},
			outLogin() {
				let promise = TUIChatEngine.logout();
				promise.then(function(imResponse) {
					console.log(imResponse.data,777); // 登出成功
				}).catch(function(imError) {
					console.warn('logout error:', imError);
				});

				this.$store.commit('reset')
				this.$api.default.request('user/logout', {}, 'GET', false).then((res) => {
					if (res.code) {
						this.$db.clear()
						uni.setStorageSync("is_looks",1)
						this.$common.successToShow(res.msg, () => {
							uni.redirectTo({
								url: '/pages/login/login'
							})
						})

					}
				})
			},
			getUserInfo() {
				this.$api.default.request('user/userInfo', {}, 'GET', false).then((res) => {
					if (res.code) {
						this.userInfo = res.user
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}

	.content {
		padding-top: 20rpx;

		.baibox {
			background-color: #ffffff;
			padding: 0 68rpx;
			margin-bottom: 20rpx;

			.baili:last-child {
				border: none;
			}

			.baili {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 120rpx;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);

				.pic {
					width: 50rpx;
					height: 50rpx;
					flex-shrink: 0;
				}

				.txt {
					flex-grow: 1;
					padding: 0 16rpx;
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
				}

				.rarr {
					width: 40rpx;
					height: 40rpx;
					flex-shrink: 0;
				}
			}
		}

		.tuibox {
			height: 120rpx;
			background-color: #ffffff;
			display: flex;
			align-items: center;
			justify-content: center;

			.tpic {
				width: 40rpx;
				height: 40rpx;
			}

			.ttxt {
				font-size: 28rpx;
				font-weight: bold;
				letter-spacing: 0em;
				color: #3D3D3D;
				padding-left: 16rpx;
			}
		}
	}
</style>